/**
 *  @file KVPairT.h
 */
#ifndef _KVPAIRT_H_
#define _KVPAIRT_H_

#include "../common/BaseObject.h"
#include "../text/CFString.h"

namespace cppflib
{

namespace collections
{

/**
 *  A class just to contain a pair of key and value (or name/value)
 */
template <class KEYT, class VALT>
class KVPairT : public BaseObject
{
private:
   BaseObject *pKey;
   BaseObject *pVal;

   KVPairT(void)
   {
      pKey = NULL;
      pVal = NULL;
   }

public:
   KVPairT(KEYT *pKey, VALT *pVal)
   {
      this->pKey = NULL;
      this->pVal = NULL;
      SetKey(pKey);
      SetVal(pVal);
   }

   virtual ~KVPairT(void)
   {
      cppmempool::Release(this->pKey);
      cppmempool::Release(this->pVal);
   }

   KEYT *GetKey() const
   {
      return static_cast<KEYT*>(this->pKey);
   } 

   VALT *GetVal() const
   {
      return static_cast<VALT*>(this->pVal);
   }

   void SetKey(KEYT *pKey)
   {
      cppmempool::Retain(pKey);
      cppmempool::Release(this->pKey);
      this->pKey = pKey;
   }

   void SetVal(VALT *pVal)
   {
      cppmempool::Retain(pVal);
      cppmempool::Release(this->pVal);
      this->pVal = pVal;
   }

};


//! A useful alias
typedef KVPairT<CFString, CFString> NameValuePair;

} // end of namespace collections


} // end of namespace cppflib


#endif
